//
//  GlobTool.m
//  爆米花视频
//
//  Created by mac on 14-11-3.
//  Copyright (c) 2014年 mac. All rights reserved.
//

#import "GlobTool.h"
#import "PushTool.h"
#import "SFHFKeychainUtils.h"
#import "AppUpdate.h"


@implementation GlobTool
singleton_implementation(GlobTool)
- (id)init
{
    if (self = [super init]) {
        _deviceToken = @"";
        _isHaveNewVersion = NO;
    }
    return self;
}

#pragma mark 初始化用户配置
- (void)initUserConfig
{
    
    [self tishiBoundID];

}
+ (NSString *)getIOSuuid {

    NSString *strUUID =  [SFHFKeychainUtils getPasswordForUsername:@"youSeUid" andServiceName:@"com.youSeshiliao.BeautyVideos" error:nil];
    if (strUUID.length == 0 || !strUUID) {
        CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault);
        strUUID = (NSString *)CFBridgingRelease(CFUUIDCreateString (kCFAllocatorDefault,uuidRef));
        [SFHFKeychainUtils storeUsername:@"youSeUid" andPassword:strUUID forServiceName:@"com.youSeshiliao.BeautyVideos" updateExisting:YES error:nil];
    }

    return [NSString stringWithFormat:@"lkj%@",strUUID];
}
//配置推广位置
- (void)tuiGuangIndex {
    [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"PubNumber"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
    [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"PubList"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
    [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"CinemePhto"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
    [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"NovelPhto"];
    [[NSUserDefaults standardUserDefaults] synchronize];

}
- (void)tishiBoundID {
    [PushTool appUpdateSuccess:^(AppUpdate *update) {
        
        self.upappUrl = update.url;
        self.appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
        if ([update.versionNum intValue] > [self.appVersion intValue]) {
            if(update.forcedUpdating > 0)
            {
                UIAlertView *appAlertView = [[UIAlertView alloc] initWithTitle:nil message:update.explain delegate:self cancelButtonTitle:nil otherButtonTitles:@"立即更新", nil];
                [appAlertView show];
            }else
            {
                UIAlertView *appAlertView = [[UIAlertView alloc] initWithTitle:nil message:update.explain delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"立即更新", nil];
                [appAlertView show];
            }
            
        } else {
            
            NSLog(@"=====已是最高版本");
        }
    } failure:^(NSError *error) {
    }];
    
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    
    if (buttonIndex == 1) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.upappUrl]];
    }
}



@end
